    import com.slothought.rowgazer.*;
    
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.SQLWarning;
    
    final static String driverClass    = "com.mysql.jdbc.Driver";
    final static String connectionURL  = "jdbc:mysql://localhost";
    final static String userID         = "tlee";
    final static String userPassword   = "test1234";
    final static String tableName     = "event";
    final static String catalogName   = "meventa";
    final static String schemaName    = null;
    java.sql.Connection   con                   = null;

   

    try {
        Class.forName(driverClass).newInstance();
         
        con = DriverManager.getConnection(connectionURL, userID, userPassword);
       
        DatabaseMetaData md = con.getMetaData() ;    
    
        ResultSet rs =  md.getExportedKeys(catalogName, schemaName, tableName);
 
        tmpData = [:]
        
        
        
        while (rs.next()){
            //String pkTableName = rs.getString("PKTABLE_NAME");
            String pkColumnName = rs.getString("PKCOLUMN_NAME");
            String fkTableName = rs.getString("FKTABLE_NAME");
            String fkColumnName = rs.getString("FKCOLUMN_NAME");
            String fkName = rs.getString("FK_NAME");
            println pkColumnName + " " + fkTableName + " " + fkColumnName + " " + fkName
            
            if (tmpData[(fkName)] == null){
                ReferentialConstraint tmpConstraint = new ReferentialConstraint();
                tmpConstraint.tableTarget = fkTableName;
                tmpConstraint.fieldMapping[(pkColumnName)] = (fkColumnName);
                tmpConstraint.isReferencing = true;
                
                tmpData[(fkName)] = [    
                                         columns : [pkColumnName] as Set,
                                         constraint : tmpConstraint,
                                         fkName : fkName
                                    ]
               
            }
            else{
            
                tmpData[(fkName)].columns.add(pkColumnName);
                tmpData[(fkName)].constraints.fieldMapping[(pkColumnName)] = (fkColumnName);
            
            }
            
            
        }
         
        println tmpData
        
        GazerMetaResult result 
        
        
        
        result = tmpData.inject(new GazerMetaResult()){ data,  entry ->
           println data.class
          
        
           FieldSet fs = new FieldSet();
           println entry.value.columns
           fs.fields = (entry.value.columns);
           fs.references[(entry.value.fkName)]= entry.value.constraint;
           
           data.fieldsets.add(fs);
           
           return data
        }
        
        result.table = tableName
        
        println result.fieldsets
       // ResultSet rset = md.getExportedKeys('meventa', 

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }


   

     



    try {
            System.out.print("  Closing Connection...\n");
            con.close();
            
        } catch (SQLException e) {
        
            e.printStackTrace();
            
        }